var rootDocment = 'https://wuye.airaic.com';
//var rootDocment = 'http://192.168.0.101:9392';
const app = getApp()

function req({
  url: url,
  data: data,
  method: method,
  header: header,
  success: successCallback,
  fail: failCallback
}) {
  wx.request({
    url: rootDocment + url,
    data: data,
    method: method,
    header: header,
    success: function (res) {
      console.log("11111", res.data)
      if (res.data.code == 401 || res.data.code == 410) {
        wx.navigateTo({
          url: '/pages/login/login',
        })
      } else if (res.data.code == 200) {
        if (res.data.msg != '登陆失效，请重新登录') {
          return typeof successCallback == "function" && successCallback(res)
        } else {
          wx.navigateTo({
            url: '/pages/login/login',
          })
        }
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
        return typeof successCallback == "function" && successCallback(res)
      }

    },
    fail: function () {
      return typeof failCallback == "function" && failCallback()
    }
  })
}


module.exports = {
  req: req
}